<?php
/**
 * Created by PhpStorm.
 * User: hooshim
 * Date: 2014-12-03
 * Time: 오전 11:23
 */

header("Content-Type:text/html;charset=utf-8");
header("Cache-Control:no-cache");
header("Pragma:no-cache");

include_once ($_SERVER['DOCUMENT_ROOT']."/inc/conn.inc.php");
include_once ($_SERVER['DOCUMENT_ROOT']."/inc/function.inc.php"); ##property 파일 인크루드됨.

	//## 파라미터 선언

//var param = "incCd=" + $("#incCd").val();
//param += "&incomeDt=" + $("#incomeDt").val();
//param += "&income=" + $("#income").val().split(',').join('');
//param += "&amount=" + $("#amount").val().split(',').join('');
//param += "&orgAmount=" + $("#orgAmount").val().split(',').join('');
//param += "&tax=" + $("#tax").val();
//param += "&compCd=" + $("#compCd").val();
//param += "&memo=" + $("#memo").val();
//param += "&flag=" + $("#flag").val();
//param += "&incSeq=" + $("#incSeq").val();
//param += "&incAmount=" + $("#incAmount").val().split(',').join('');
//param += "&actionDt=" + $("#actionDt").val();
//param += "&bankDt=" + $("#bankDt").val();
//param += "&incMemo=" + $("#memo").val();

    $incCd 			= $_POST['incCd'];
    $billCd 		= $_POST['billCd'];
    $invoiceCd 		= $_POST['invoiceCd'];
    $invoiceMemo 	= $_POST['invoiceMemo'];
    $incomeDt 		= $_POST['incomeDt'];
    $income 		= $_POST['income'];
    $amount 		= $_POST['amount'];
    $orgAmount 		= $_POST['orgAmount'];
    $tax 			= $_POST['tax'];
    $compCd 		= $_POST['compCd'];
    $memo 			= $_POST['memo'];
    $flag 			= $_POST['flag'];
    $incSeq 		= $_POST['incSeq'];
    $incAmount 		= $_POST['incAmount'];
    $actionDt 		= $_POST['actionDt'];
    $bankDt 		= $_POST['bankDt'];
    $incMemo 		= $_POST['incMemo'];
    $incFlag 	    = $_POST['incFlag'];

    if($income) $income = iconvEncode($income);
    if($memo) $memo = iconvEncode($memo);
    if($incMemo) $incMemo = iconvEncode($incMemo);
    if($invoiceMemo) $invoiceMemo = iconvEncode($invoiceMemo);

    if(!$amount) $amount = 0;
    if(!$orgAmount) $orgAmount = 0;
    if(!$tax) $tax = 0;
    if(!$incAmount) $incAmount = 0;
    if(!$compCd) $compCd = 0;
    if(!$incSeq) $incSeq = 0;
    if(!$incCd) $incCd = 0;
    if(!$billCd) $billCd = 0;
    if($incAmount == 0 || !$incAmount) {
        $bankDt = "";
        $actionDt = "";
    }

//@income varchar(100),					-- 내역
//	@ varchar(10),				-- 입금일
//	@accountCd int,							-- 계정코드
//	@memo varchar(500),					-- 메모
//	@amount numeric(18,0),				-- 금액
//	@orgAmount numeric(18,0),			-- 원금
//	@tax numeric(18,0),						-- 세금
//	@accessId varchar(20),					-- 등록자 ID
//	@incCd int,										-- 시퀀스
//	@compCd int,								-- 회사코드
//	@flag varchar(2),							-- 가용여부
//	@invoiceCd int = 0,						-- 거래명세서 코드
//	@invoiceMemo varchar(200)='',	-- 거래명세서 메모
//	@billCd varchar(15)='',					-- Bill No
//	@incAmount numeric(18,0) = 0,   -- 입금액
//	@actionDt varchar(10) = '',			-- 입금일
//	@bankDt varchar(10) = '',				-- 통장일
//	@incMemo varchar(500) = '',		-- 입금메모
//	@incFlag varchar(2) = 'Y',				-- 입금내역 가용여부
//	@incSeq int = 0								-- 입금내역 시퀀스

//    $stmt = mssql_init('spExpress');

    if(!$issueId) $issueId = "Jade";

    $query = "EXEC spIncome ";

    $query .=" @income='" .$income ."'";
    $query .=", @incomeDt='" .$incomeDt ."'";
    $query .=", @memo='" .$memo ."'";
    $query .=", @amount='" .$amount ."'";
    $query .=", @orgAmount='" .$orgAmount ."'";
    $query .=", @tax='" .$tax ."'";
    $query .=", @accessId='" .$issueId ."'";
    $query .=", @incCd='" .$incCd ."'";
    $query .=", @compCd='" .$compCd ."'";
    $query .=", @flag='" .$flag ."'";
    $query .=", @invoiceCd='" .$invoiceCd ."'";
    $query .=", @invoiceMemo='" .$invoiceMemo ."'";
    $query .=", @billCd='" .$billCd ."'";
    $query .=", @incAmount='" .$incAmount ."'";
    $query .=", @actionDt='" .$actionDt ."'";
    $query .=", @bankDt='" .$bankDt ."'";
    $query .=", @incMemo='" .$incMemo ."'";
    $query .=", @incSeq='" .$incSeq ."'";
    $query .=", @incFlag='" .$incFlag ."'";

    $logger->debug($query ." [#FROM:" . $G_remote_ip."#]"); ## 결과 로그 작성
//    $query = iconvEncode($query);
    $rslt = mssql_query($query);
$logger->debug($rslt ." [#FROM:" . $G_remote_ip."#]");

    $result = Array();
    if ($rslt == "1") {
        $result['rsStatus'] = "Success";
        $successMsg = iconvEncode("저장 되었습니다.");
    }
    else {
        $result['rsStatus'] = "Fail";
        $successMsg = iconvEncode("저장 실패");

    }
    $result['rsStr'] = urlencode($successMsg);

    $output = json_encode($result);
    $output = urldecode($output);
    echo iconvDecode($output);
    $logger->debug($output ." [#FROM:" . $G_remote_ip."#]"); ## 결과 로그 작성
?>